<?php namespace web\home\controller;

class Entry extends Common{
	//首页
	public function index() {
		//title标签数据
		$conf = ['title'=>'莜莜博客-首页'];
		View::with('conf',$conf);
		//文章
		$page = Page::row(5)->make(Db::table(article)->where('is_recycle',1)->count());
		$articleData = Db::table('article')
			//文章表与分类表关联
			->join('category','category_cid','=','cid')
			->where('is_recycle',1)->limit(Page::limit())
			->get();
		foreach ($articleData as $k => $v){
//			p($articleData);
			$articleData[$k]['tag']=Db::table('article_tag')
				//中间表和标签表关联
				->join('tag','tag_tid','=','tid')
				->where('article_aid',$v['aid'])
				//获取tid tname 俩个字段
				->field(['tid','tname'])
				->get();
		}
		View::with('page',$page);
		View::with('articleData',$articleData);
		//p($articleData);
		View::make();
	}


	public function theme(){
		$theme = q('get.theme');
		Db::table('webset')->where("name",'theme')->update(['value'=>$theme]);
		go('index');
	}


}